#!/opt/local/bin/python
import sys

old_itemid = None

for l in sys.stdin:
    l = l.strip()
    p = l.split()
    itemid = p[0]
    uid = p[1]
    rating = int(p[2])
    
    if old_itemid is None or old_itemid != itemid:
        ll = []
        if old_itemid is not None:

            for k,v in u_map.iteritems():
                lll = []
                for kk,vv in v.iteritems():
                    lll.append("%s:%s" % (kk,vv))
                    l_s = ",".join(lll)
                ll.append("%s;%s" % (k,l_s))

            print old_itemid , " ".join(ll)            

        old_itemid = itemid 
        u_map = {}

    if old_itemid == itemid:
        if uid not in u_map:
            u_map[uid] = {}
        if rating == 1:
            u_map[uid][rating] = 0
        elif rating == -1:
            u_map[uid][rating] = 0
        u_map[uid][rating] += 1    

ll = []
for k,v in u_map.iteritems():
    lll = []
    for kk,vv in v.iteritems():
        lll.append("%s:%s" % (kk,vv))
        l_s = ",".join(lll)
    ll.append("%s;%s" % (k,l_s))

print old_itemid , " ".join(ll)            




